#ifndef VL_SOCKETS_HPP
#define VL_SOCKETS_HPP

#if defined(WIN32) || defined(_WIN32)
#define WINDOWS
#endif

#include <string>
#include <cassert>

namespace vl
{

extern int const sockerr_in_progress;
extern int const sockerr_would_block;

extern int const sock_error_ret;

struct socket
{
	socket();
	
	bool valid();
	
	void close();
	
	union
	{
		int   _int;
		void* _voidp;
	};
};

struct host_entry;
struct internet_sockaddr;

int sock_error();

host_entry* resolve_host(std::string const& name);
void delete_host(host_entry* p);

socket socket_nonblock();

void set_no_blocking(socket s);

bool set_no_delay(socket s, int no_delay = 1);

bool bind(socket s, int port);

bool listen(socket s);

socket accept(socket s, internet_sockaddr& addr);

bool connect(socket s, internet_sockaddr& addr);

bool create_addr(internet_sockaddr& addr, host_entry* hp, int port);

#ifdef WINDOWS
void init_sockets();

void deinit_sockets();
#else
inline void init_sockets() {}

inline void deinit_sockets() {}
#endif

}

#endif //VL_SOCKETS_HPP
